//
//  OIPubListViewController.m
//  EducationOID
//
//  Created by slz on 2017/5/25.
//  Copyright © 2017年 bnsr. All rights reserved.
//

#import "OIPubListViewController.h"
#import "OIPubListTableViewAdapter.h"
#import "OIPubListModel.h"


@implementation PubListTableHeadView

-(instancetype)init
{
    self = [super init];
    if (self){
        UIImageView * image = [UIImageView new];
        image.image = [UIImage imageNamed:@"icon_public_circle_teeth"];
        [self addSubview:image];
        [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(16, 15));
            make.left.mas_equalTo(self.mas_left).offset(11);
            make.centerY.mas_equalTo(self.mas_centerY);
        }];
        
        _titleLabel = [UILabel new];
        _titleLabel.textColor = kBlue_Color_Default;
        _titleLabel.fontSize = 16;
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.mas_centerY);
            make.left.mas_equalTo(image.mas_right).offset(10);
        }];
        
        UIView * lineView = [UIView new];
        lineView.backgroundColor = kBack_Color_Default;
        [self addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left).offset(11);
            make.right.mas_equalTo(self.mas_right).offset(-11);
            make.height.mas_equalTo(3);
            make.bottom.mas_equalTo(self.mas_bottom).offset(-10);
        }];
    }
    return self;
}

@end

@interface OIPubListViewController ()<TGMMode2TableViewAdapterDelegate>
@property (nonatomic,strong) YWTableView *tableView;
@property (nonatomic,strong) PubListTableHeadView *tableHeaderView;
@end

@implementation OIPubListViewController
{
    OIPubListTableViewAdapter *_tableAdapter;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.showNavigationBar = YES;
    [self setControllerTitle:_isPub ? @"OID注册发布列表" : @"OID注册公示列表"];
    self.view.backgroundColor = kBack_Color_Default;
    UIBarButtonItem * item = [UIBarButtonItem itemWithImage:@"top_back_1" selectImage:nil addTarget:self andAction:@selector(backAction)];
    self.navigationItem.leftBarButtonItem = item;
    [self initTableView];
    
    // Do any additional setup after loading the view.
}

- (void)initTableView{
    _tableHeaderView = [[PubListTableHeadView alloc]init];
    _tableHeaderView.titleLabel.text = _isPub ? @"OID注册发布列表" : @"OID注册公示列表";
    _tableHeaderView.size = CGSizeMake(kScreenWidth, 80);
    
    _tableView = [[YWTableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    [_tableView setTableHeaderView:_tableHeaderView];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
    _tableAdapter = [[OIPubListTableViewAdapter alloc]init];
    _tableAdapter.contextViewController = self;
    _tableAdapter.isPub = _isPub;
    [_tableAdapter bindTableView:_tableView withModel:[OIPubListModel managedModelInstance] actionData:[[OIPubListModel managedModelInstance]actionDataWithPub:_isPub] atOffsetY:0];
    [_tableAdapter requestRefresh];
}

-(void)onReloadData:(TGMModel2ScrollViewAdapter *)adapter{
    NSLog(@"asad");
}

- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
